<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="第三方登录id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sysUserId">
              <j-dict-select-tag type="list" v-model="model.sysUserId" :dictCode="querySelect.sysUserIdSelect" placeholder="请选择第三方登录id" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="头像" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="avatar">
              <j-image-upload style='' bizPath='ora/useravatar' v-model='model.avatar'></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="冻结状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="status">
              <j-dict-select-tag type="list" v-model="model.status" dictCode="user_status" placeholder="请输入状态(1-正常,2-冻结)" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="删除状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="delFlag">
              <j-dict-select-tag type="list" v-model="model.delFlag" dictCode="del_flag" placeholder="删除状态(0-正常,1-已删除)" />

            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="真实姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="realname">
              <a-input v-model="model.realname" placeholder="请输入真实姓名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="第三方账号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="thirdUserUuid">
              <a-input v-model="model.thirdUserUuid" placeholder="请输入第三方账号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="第三方app用户账号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="thirdUserId">
              <a-input v-model="model.thirdUserId" placeholder="请输入第三方app用户账号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="登录来源" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="thirdType">
              <j-dict-select-tag type="list" v-model="model.thirdType" dictCode="third_type" placeholder="请选择登录来源" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'
  import ImagPreview from '@views/jeecg/ImagPreview'
  import Vue from 'vue'
  import { TENANT_ID } from '@/store/mutation-types'

  export default {
    name: 'SysThirdAccountExtendForm',
    components: {
      ImagPreview
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        querySelect:{
          sysUserIdSelect: "sys_user,concat_ws('' !! realname !! '(' !! username !! ')'),id,del_flag  =0 and tenant_id = '"+Vue.ls.get(TENANT_ID)+"' order by to_pinyin(realname )"
        },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/systemextend/systemextend/sysThirdAccountExtend/add",
          edit: "/systemextend/systemextend/sysThirdAccountExtend/edit",
          queryById: "/systemextend/systemextend/sysThirdAccountExtend/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
      initsysUserIdSelect();
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
        initsysUserIdSelect(){
          let tenantId = Vue.ls.get(TENANT_ID);
          if(tenantId){
            this.querySelect.sysUserIdSelect= "sys_user,concat_ws('' !! realname !! '(' !! username !! ')'),id,del_flag  =0 and tenant_id = '"+tenantId+"' order by to_pinyin(realname )"
          }
          else{
            this.querySelect.sysUserIdSelect= "sys_user,concat_ws('' !! realname !! '(' !! username !! ')'),id,del_flag  =0  order by to_pinyin(realname )"
          }

    },
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }

        })
      },
    }
  }
</script>